import axios from '@/utils/request';

/**
 * 新增销售订单
 */
export async function AddSaleorder(params) {
    const res = await axios.post('/SaleOrder/AddSaleorder',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取销售订单查询分页列表
 */
 export async function QuerySaleorderByCondition(params) {
    const res = await axios.post('/SaleOrder/QuerySaleorderByCondition',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 获取销售订单带批次号数据集
 */
export async function QuerySaleorderBatchNoByCondition(params) {
    const res = await axios.post('/SaleOrder/QuerySaleorderBatchNoByCondition',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}




/**
 * 作废销售订单
 */
export async function DeleteSaleorder(id) {
    const res = await axios.post('/SaleOrder/DeleteSaleorder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id获取采购订单
 */
 export async function QuerySaleorderById(id) {
    const res = await axios.get('/SaleOrder/QuerySaleorderById/'+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id获取采购订单
 */
export async function QuerySaleorderByIdandBactNo(params) {
    const res = await axios.post('/SaleOrder/QuerySaleorderByIdandBactNo',params);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 打印
 */
export async function PrintSaleOrderById(id) {
    const res = await axios.post('/SaleOrder/PrintSaleOrderById?id='+id);
    if (res.data.code === 200) {
        return res.data.data;
    }
    return Promise.reject(new Error(res.data.msg));
}


/**
 * 更新销售订单
 */
 export async function UpdateSaleorder(params) {
    const res = await axios.post('/SaleOrder/UpdateSaleorder',params);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 反单
 */
export async function AnitSaleorder(id) {
    const res = await axios.post('/SaleOrder/AnitSaleorder?id='+id);
    if (res.data.code === 200) {
        return res.data.msg;
    }
    return Promise.reject(new Error(res.data.msg));
}

/**
 * 导入订单
 */
export async function ImportExcel(formData) {
    // const res = await axios.post('/SaleOrder/ImportExcel',);
    // if (res.data.code === 200) {
    //     return res.data;
    // }
    // return Promise.reject(new Error(res.data.msg));

    const res = await axios.post('/SaleOrder/ImportExcel',formData,{headers: {
        'Content-Type': 'multipart/form-data'
       }});
    return res.data;
}

